/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cxhd.lis.model.newmodel;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Record;
import java.util.Date;
import java.util.List;

/**
 *
 * @author cxhd
 */
public class LisDeviceset extends Model<LisDeviceset>{
    public static LisDeviceset lisDevicesetdao=new LisDeviceset();
      
    public void deleteLisDevice(String PK){
         Db.use("mysql").update("delete from lis_deviceset where PK=?",Integer.valueOf(PK));
        
     }
     
     public void saveNewLisDevice(String DEVICEMODEL,String DEVICENAME,String FACTORY,String DEVICESTATUS,String PATH,String COMPORTN,String BAUDRATES,String DEVICETYPEPK,String KSMCPK,String NOTES,String JUDGE ){  
//         select PK,DEVICEID,DEVICETYPE,DEVICEMODEL,DEVICENAME,FACTORY,USEDEPARTMENT,DEVICESTATUS from lis_deviceset;
                set("DEVICEID", DEVICEMODEL)
//         .set("DEVICETYPE", DEVICETYPE)               
                 .set("DEVICEMODEL", DEVICEMODEL)
                 .set("DEVICENAME", DEVICENAME)
                 .set("FACTORY", FACTORY)
                          .set("NOTES", NOTES)
                            .set("JUDGE", JUDGE)
//                 .set("USEDEPARTMENT", USEDEPARTMENT)//使用部门
                 .set("PATH",PATH )
                 .set("INSTALLDATE", new Date())
                  .set("DEVICESTATUS", DEVICESTATUS)
                        //以下使用默认值的均待商议
//                 String DEVICETYPEPK,String KSMCPK 
                 .set("COMPORTN",COMPORTN ) //串口
                 .set("BAUDRATES",BAUDRATES )//波特率
                 .set("DEVICETYPEPK", DEVICETYPEPK)
                 .set("KSMCPK", KSMCPK)
                 .set("PARITYS","N" )
                 .set("DATABITS", 8)
                 .set("STOPBITS", 1 )
                 .set("HANDSHAKE", 2 )
                        
                 .save();
     }
     public void updateLisDevice(String PK,String DEVICEMODEL,String DEVICENAME,String FACTORY,String PATH,String DEVICESTATUS,String COMPORTN,String BAUDRATES,String DEVICETYPEPK,String KSMCPK,String NOTES,String JUDGE){
         
         findById(PK) 
                  .set("DEVICEID", DEVICEMODEL)
                 .set("DEVICEMODEL", DEVICEMODEL)
                 .set("DEVICENAME", DEVICENAME)
                 .set("FACTORY", FACTORY)
//                 .set("USEDEPARTMENT", USEDEPARTMENT)//使用部门
                 .set("PATH",PATH )
                    .set("NOTES", NOTES)
                  .set("JUDGE", JUDGE)
//                 .set("DEVICETYPE",DEVICETYPE)
                 .set("DEVICESTATUS",DEVICESTATUS)
                  .set("DEVICETYPEPK", DEVICETYPEPK)
                 .set("KSMCPK", KSMCPK)
                   .set("COMPORTN",COMPORTN ) //串口
                 .set("BAUDRATES",BAUDRATES )//波特率
                 .update();
                 
     }
   
     public String getDeviceId(){
           List<Record> list=Db.use("mysql").find("select * from lis_deviceset limit 0,10");
        String  value = "1";
        if(list.size()>0){
           value = (Integer.parseInt(Db.use("mysql").findFirst("SELECT MAX(DEVICEID) as id from lis_deviceset ").get("id") + "") + 1) + "";
        }
         System.out.println(value);
      return value;
      }
     

}
